<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>主界面</title>
    <script src="../js/cookie.js"></script>
</head>
<style>
    .wrap {
        width: 300px;
        height: 200px;
        border: 1px solid #333;
        margin: 100px auto;
        text-align: center;
        line-height: 200px;
    }
</style>

<body>
    <div class="wrap">
        <div class="box">欢迎xxx</div>
        <button class="login">去登录</button>
        <button class="del">退出登录</button>
    </div>
</body>
<script>
    var box = document.querySelector(".box");
    var delBtn = document.querySelector(".del");
    var loginBtn = document.querySelector(".login");
    
    if (getCookie("ski")) {
        console.log("欢迎" + getCookie("user"));
        box.textContent = `欢迎${getCookie("user")}登录！`;
    } else {
        box.textContent = `亲，请登录噢！`;
    }

    loginBtn.onclick = function() {
        location.href = "login.html";
        // history.back();
    }

    delBtn.onclick = function () {
        delCookie("ski");
        location.reload();
    }
</script>

</html>